package com.anxin.controller;

import com.anxin.entity.Schedule;
import com.anxin.service.ScheduleService;
import com.anxin.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDate;
import java.util.List;

@Tag(name = "排班管理")
@RestController
@RequestMapping("/api/schedule")
public class ScheduleController extends BaseController {
    @Autowired
    private ScheduleService scheduleService;

    @Operation(summary = "获取医生的排班列表")
    @GetMapping("/doctor/{doctorId}")
    public Result<List<Schedule>> getSchedulesByDoctorId(@Parameter(description = "医生ID") @PathVariable String doctorId) {
        return Result.success(scheduleService.getSchedulesByDoctorId(doctorId));
    }

    @Operation(summary = "获取医生指定日期的排班")
    @GetMapping("/doctor/{doctorId}/date/{date}")
    public Result<List<Schedule>> getSchedulesByDoctorIdAndDate(
            @Parameter(description = "医生ID") @PathVariable String doctorId,
            @Parameter(description = "日期") @PathVariable String date) {
        return Result.success(scheduleService.getSchedulesByDoctorIdAndDate(doctorId, LocalDate.parse(date)));
    }

    @Operation(summary = "添加排班")
    @PostMapping("/add")
    public Result<Void> addSchedule(@RequestBody Schedule schedule) {
        scheduleService.addSchedule(schedule);
        return Result.success();
    }

    @Operation(summary = "更新排班")
    @PutMapping("/update")
    public Result<Void> updateSchedule(@RequestBody Schedule schedule) {
        scheduleService.updateSchedule(schedule);
        return Result.success();
    }

    @Operation(summary = "删除排班")
    @DeleteMapping("/delete/{id}")
    public Result<Void> deleteSchedule(@Parameter(description = "排班ID") @PathVariable String id) {
        scheduleService.deleteSchedule(id);
        return Result.success();
    }
}
